package com.atguigu.flink.chapter10;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2023/6/27 09:23
 */
public class KafkaConsumeUpsertKafka {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 4000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        env.enableCheckpointing(3000);
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        // 通过 ddl 的方式创建连接器表
        tEnv.executeSql("create table sensor(" +
                            " id string, " +
                            " vc_sum int " +
                            ")with(" +
                            "  'connector' = 'kafka', " +
                            "  'topic' = 's2_upsert', " +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
                            "  'properties.group.id' = 'abc', " +
                            "  'scan.startup.mode' = 'earliest-offset', " +
                            "  'format' = 'json' " +
                            ")");
        
        tEnv.sqlQuery("select * from sensor").execute().print();
        
        
        
    
      
    
    
    }
}
